package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.Introduction;
import com.fsnbigdata.domain.PlantConservation;
import com.fsnbigdata.domain.QIntroduction;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = IntroductionRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = IntroductionRepositoryCustom.class)
@Transactional(readOnly = true)
public class IntroductionRepositoryImpl extends QueryDslRepositorySupportExt<Introduction> implements IntroductionRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    IntroductionRepositoryImpl() {
        super(Introduction.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ADD_MONTH = "addMonth";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String COUNTRY = "country";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String QUANTITY = "quantity";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ADD_DAY = "addDay";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PLANT_CONSERVATION = "plantConservation";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ADD_YEAR = "addYear";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PROVINCE = "province";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String MATERIAL_NAME = "materialName";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String RECORDER = "recorder";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String INTRO_NO = "introNo";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String COUNTY = "county";

    /**
     * TODO Auto-generated method documentation
     *
     * @param plantConservation
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<Introduction> findByPlantConservation(PlantConservation plantConservation, GlobalSearch globalSearch, Pageable pageable) {
        QIntroduction introduction = QIntroduction.introduction;
        JPQLQuery<Introduction> query = from(introduction);
        Assert.notNull(plantConservation, "plantConservation is required");
        query.where(introduction.plantConservation.eq(plantConservation));
        Path<?>[] paths = new Path<?>[] { introduction.plantConservation, introduction.introNo, introduction.addYear, introduction.addMonth, introduction.addDay, introduction.materialName, introduction.quantity, introduction.recorder, introduction.country, introduction.province, introduction.county };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(PLANT_CONSERVATION, introduction.plantConservation).map(INTRO_NO, introduction.introNo).map(ADD_YEAR, introduction.addYear).map(ADD_MONTH, introduction.addMonth).map(ADD_DAY, introduction.addDay).map(MATERIAL_NAME, introduction.materialName).map(QUANTITY, introduction.quantity).map(RECORDER, introduction.recorder).map(COUNTRY, introduction.country).map(PROVINCE, introduction.province).map(COUNTY, introduction.county);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, introduction);
    }
}
